package com.turnengine.client.local.unit.list.count;

import static com.javabi.common.dependency.DependencyFactory.getDependency;

import java.util.List;

import com.turnengine.client.local.unit.IUnitCache;
import com.turnengine.client.local.unit.bean.IUnitCount;
import com.turnengine.client.local.unit.enums.UnitType;

public class UnitCountListVerifier implements IUnitCountListVerifier {

	private final IUnitCountListSplitter splitter;
	private final UnitListToCountListAdaptor adaptor;

	public UnitCountListVerifier(IUnitCache unitCache) {
		this.adaptor = new UnitListToCountListAdaptor(unitCache);
		this.splitter = new UnitCountListSplitter();
	}

	public UnitCountListVerifier() {
		this(getDependency(IUnitCache.class));
	}

	@Override
	public List<IUnitCount> splitAndVerify(List<IUnitCount> list, UnitType type) {
		list = splitter.splitList(list, type);
		adaptor.adapt(list, type);
		return list;
	}

	@Override
	public void verify(List<IUnitCount> list) {
		splitAndVerify(list, UnitType.PLAYER);
		splitAndVerify(list, UnitType.LOCATION);
		splitAndVerify(list, UnitType.MOBILE);
	}

}
